package com.polyGeek.utils {
	import flash.display.Loader;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.system.LoaderContext;
	
	import spark.primitives.BitmapImage;
	
	public class BMP extends BitmapImage {
		
		private var _loader:Loader;
		private var _filename:String;
		private var _context:LoaderContext;
		
		public function BMP(){
			super();
			_loader = new Loader();
			_context = new LoaderContext();
			_context.checkPolicyFile = true;
		}
		
		private function loadBMP():void {
			_loader.contentLoaderInfo.addEventListener( Event.COMPLETE, onBMPloaded );
			_loader.load( new URLRequest( filename ), _context );
		}
		
		private function onBMPloaded( e:Event ):void {
			_loader.contentLoaderInfo.removeEventListener( Event.COMPLETE, onBMPloaded );
			this.source = _loader.content;
		}
		
		// GET/SET filename
		public function set filename( s:String ):void {
			if( s == _filename ) {
				return;
			}
			_filename = s;
			loadBMP();
		} 
		
		public function get filename():String {
			return _filename;
		}
	}
}